﻿using System.ComponentModel.DataAnnotations;

namespace Provenance.ErrorCount
{
    public class ApiResult
    {
        public bool IsSuc { get; set; }
        public string Msg { get; set; }=string.Empty;
        public ApiResultEnum Code { get; set; }
        public ApiResult(bool isSuc, string msg, ApiResultEnum code)
        {
            IsSuc = isSuc;
            Msg = msg;
            Code = code;
        }
        public static ApiResult Success()
        {
            return new ApiResult(true,"操作成功",ApiResultEnum.Ok);
        }
        public static ApiResult Failure(string msg="操作失败")
        {
            return new ApiResult(false,msg,ApiResultEnum.Fail);
        }
    }
    public class ApiResult<T> : ApiResult
    {
        public T? Data { get; set; }
        public ApiResult(bool isSuc, string msg, ApiResultEnum code,T? data) : base(isSuc, msg, code)
        {
            Data = data;
        }
        public static ApiResult<T> Success(T ? data)
        {
            return new ApiResult<T>(true,"操作成功",ApiResultEnum.Ok,data);
        }
        public new static ApiResult<T> Failure(string msg="操作失败")
        {
            return new ApiResult<T>(false,msg,ApiResultEnum.Fail,default);
        }
    }
}
